/**
 * Created by sxx on 2017/5/6.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";

jQuery(function () {
    App.init();
    let token = sessionStorage.getItem('supplier_token');
    let splrId = sessionStorage.getItem('splrId');
    var projId = getArgs().id;

    $('.J_return').click(function(){
        window.history.back();
    });

    jQuery.ajax({
        url: HOST_ADDR+'/cpmp/xjProjMngForSplr/viewXjProjDtl/'+projId,
        type: 'get',
        dataType: 'json',
        contentType:"application/json",
        headers: {
            'access_token': token,
            'login_type': 'splr'
        },
        success: function(resp){
            if (!resp.success) {
                console.log(resp.msgCod+' '+resp.msgInf);
                return;
            }
            var projqotCntTyp='非实时报价',bidRngTyp='非定向招标';
            if (resp.data.xjProj.qotCntTyp == 2) {
                projqotCntTyp='实时报价';
            }
            if (resp.data.xjProj.bidRngTyp == 1) {
                bidRngTyp='定向招标';
            }

            var bidOpenTim='',bidEndTim='',projMemo='',splrNames='';
            if (resp.data.xjProj.bidOpenTim != null&&resp.data.xjProj.bidOpenTim !='') {
                var bidOpenTim = (new Date(resp.data.xjProj.bidOpenTim)).Format("yyyy-MM-dd hh:mm:ss");
            }
            if (resp.data.xjProj.bidEndTim != 'null'&&resp.data.xjProj.bidEndTim !='') {
                var bidEndTim = (new Date(resp.data.xjProj.bidEndTim)).Format("yyyy-MM-dd hh:mm:ss");
            }
            if (resp.data.xjProj.projMemo != null&&resp.data.xjProj.projMemo !='') {
                var projMemo = resp.data.xjProj.projMemo;
            }
            if(resp.data.splrs){
                $.each(resp.data.splrs,function(index,item){
                    splrNames += item.splrNam + " ";
                })
            }
            console.log(resp);
            var matTyp = resp.data.xjProj.matTyp;
            if(resp.data.matTypDesc!=null && resp.data.matTypDesc!=''){
                matTyp = resp.data.matTypDesc;
            }

            // var grdRulList = {"0":"最低单价中标","1":"专家评标","2":"最低总价评标"};
            // if (typeof(resp.data.xjProj.grdRul) == 'undefined' || resp.data.xjProj.grdRul == null
            //     || resp.data.xjProj.grdRul == '' || resp.data.xjProj.grdRul == '0') {
            //     resp.data.xjProj.grdRulFmt = '最低单价中标';
            // } else {
            //     resp.data.xjProj.grdRulFmt = grdRulList[resp.data.xjProj.grdRul];
            // }
            // if(typeof(resp.data.xjProj.projSupv) == 'undefined' || resp.data.xjProj.projSupv == null){
            //     resp.data.xjProj.projSupv = '';
            // }
            // if(typeof(resp.data.xjProj.projSupvTel) == 'undefined' || resp.data.xjProj.projSupvTel == null){
            //     resp.data.xjProj.projSupvTel = '';
            // }
            jQuery('.basicInfo').append('<div class="portlet-body"><table class="table table-striped table-bordered"><tbody><tr>' +
                '<td width="16%">项目名称：</td><td colspan="2">'+resp.data.xjProj.projNam+'</td> ' +
                '<td width="16%">项目编号：</td> <td colspan="2">'+resp.data.xjProj.projNbr+'</td></tr> <tr>' +
                '<td width="16%">物料品类：</td><td colspan="2">'+matTyp+'</td>' +
                '<td width="16%">报价次数类型：</td><td colspan="2">'+projqotCntTyp+'</td></tr> <tr>' +
                '<td width="16%">招标单位：</td><td colspan="2">'+resp.data.xjProj.bidDptNam+'</td>' +
                '<td width="16%">招标单位地址：</td><td colspan="2">'+resp.data.xjProj.bidDptAddr+'</td></tr><tr>' +
                /*
                '<td width="16%">投标保证金（元）：</td><td colspan="2">'+resp.data.xjProj.bidDpst+'</td>' +
                '<td width="16%">评标规则：</td><td colspan="2">'+resp.data.xjProj.grdRulFmt+'</td></tr><tr>' +
                */
                '<td width="16%">联系人：</td><td colspan="2">'+resp.data.xjProj.ctct+'</td>' +
                '<td width="16%">联系电话：</td><td  colspan="2">'+resp.data.xjProj.ctctTel+'</td></tr><tr>' +
                /*
                '<td width="16%">监标人：</td><td colspan="2">'+resp.data.xjProj.projSupv+'</td>' +
                '<td width="16%">监标人联系电话：</td><td  colspan="2">'+resp.data.xjProj.projSupvTel+'</td></tr><tr>' +
                */
                '<td width="16%">投标开标时间：</td><td colspan="2">'+bidOpenTim+'</td>' +
                '<td width="16%">投标截止时间：</td><td colspan="2">'+bidEndTim+'</td></tr><tr>' +
                '<td>招标范围类型：</td><td colspan="2">'+bidRngTyp+'</td>' +
                '<td width="16%">指定招标供应商：</td><td colspan="2">'+splrNames+'</td></tr><tr>' +
                '<td>付款方式及其他：</td><td colspan="5">'+projMemo+'</td></tr></tbody></table></div>');
			if(resp.data.matDtls.length ==0){
				jQuery('#emptyData').hide();
			}else{
				jQuery('#emptyData').show();
			}

            var atches = resp.data.atches;
            if ((atches!=null && atches!='undefined') && atches.length > 0){
                for (var i= 0;i<atches.length;i++) {
                    jQuery('#tab_3').append('<div class="controls atchDiv"><span src="'+atches[i].atchUrl+'">'+atches[i].atchNam+'</span>' +
                        '&emsp;<a target="_blank" href="'+HOST_FILE+atches[i].atchUrl+'">查看</a></div>');
                }
            }

            for(var i = 0;i< resp.data.matDtls.length;i++) {
            	if(resp.data.matDtls[i].memo == null){
            		resp.data.matDtls[i].memo = ""; 
            	}
            	if(resp.data.matDtls[i].techServ == null){
                    resp.data.matDtls[i].techServ = "";
                }
                resp.data.matDtls[i].dlvDte = resp.data.matDtls[i].dlvDte ? (new Date(resp.data.matDtls[i].dlvDte)).Format("yyyy-MM-dd") : '';
//				console.log(resp.data.matDtls[i])
                jQuery('#new_basicInfo').after('<tr><td style="text-align:center;width: 18% !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].matNam+'</td>'+
                	'<td style="text-align:center;width: 11% !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].pchsNum+'</td>'+
                	'<td style="text-align:center;width: 8% !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].matUnt+'</td>'+
                    '<td style="text-align:center;width: 8% !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].dlvAdr+'</td>'+
                    '<td style="text-align:center;width: 8% !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].dlvDte+'</td>'+
                	'<td style="width: 25% !important;word-wrap:break-word !important;word-break:break-all !important;overflow:hidden !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].techServ+'</td>'+
                	'<td style="width: 12% !important;word-wrap:break-word !important;word-break:break-all !important;overflow:hidden !important;vertical-align:middle;display:table-cell;">'+resp.data.matDtls[i].memo+'</td></tr>'
                );
            }
        },
        error:function(err){
            console.log(err);
        }
    });

});

